<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack"%>

<chiptrack:checkLogon sourcePage="userDefinedFieldsForPojectSetup.do"/>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.forecast.commons.Constants,
                 com.scalar.forecast.commons.SessionKeys"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>
<SCRIPT language="JavaScript">
    function addRow( rowId )
    {
        var row = document.getElementById(rowId);
        var table = row.parentElement;
        var newRow = table.insertRow(row.rowIndex);
        var td = newRow.insertCell();
        td.width = "62";
        td.innerHTML="&nbsp;";
        td = newRow.insertCell();
        td.width="128";
        td.innerHTML = '<input type=text name="value" class=txfield size="25" maxlength="25" />';
        td = newRow.insertCell();
    }
    function closeWindow()
    {
        window.close();
    }
    function save()
    {
        var errors1="";
        if ( document.userDefinedFieldsForm.value.length != null )
        {
            len = document.userDefinedFieldsForm.value.length;
            xyz:
            for ( var i = 0; i < len-1; i++ ) {
                for ( var j = i+1; j < len; j++ ) {
                    if ( ( document.userDefinedFieldsForm.value[i].value ).trim() != "" && ( document.userDefinedFieldsForm.value[j].value ).trim() != "" &&
                         ( document.userDefinedFieldsForm.value[i].value ).trim() == ( document.userDefinedFieldsForm.value[j].value ).trim()
                        ) {
                        errors1 = errors1+"<br><li> Values should not be repeated"
                        break xyz ;
                    }
                }
            }
        }
        if ( errors1 == "" ) {
            document.userDefinedFieldsForm.action.value="saveList";
            document.userDefinedFieldsForm.submit();
        }
        else{
            var pa = document.getElementById("errorsId");
            pa.innerHTML = "";
            pa = document.getElementById("infoId");
            pa.innerHTML = "";
            pa = document.getElementById("error");
            pa.innerHTML = errors1;
        }
    }
</SCRIPT>

<html:form name="userDefinedFieldsForm" method="post"  action="/userDefinedFieldsForPojectSetup.do" scope="request" type="com.scalar.forecast.projectSetup.forms.UserDefinedFieldsForm" onsubmit="return false;">

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
    </TD>

    <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
        <!-- from here your body starts -->
        <TABLE border="0">
        <% if ( !user1.isActionAllowed ( Functionality.PROJECT_SETUP, User.USER_ACTION_MODIFY ) ) { %>
                    <tr><td colspan=3 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></td></tr> <% } %>
            <TR>
                <TD colspan="3" bgColor="#993333" width="263" height="16"><FONT class="NArialL" style="color:#ffffff" id="fieldLabel">&nbsp;User Defined Field: <%=request.getParameter("listName")%></FONT></TD>
            </TR>
            <TR><TD colspan ="3" class="NArialL" id="errorsId"><chiptrack:errors styleClass="NArialL" /></TD></TR>
            <TR><TD colspan ="3" class="NArialL" id="infoId"><chiptrack:info styleClass="NArialL" /></TD></TR>
            <TR><TD colspan="3" align="left" class='NArialL'><font styleClass="NArialL" id="error" color="FF0000"  />&nbsp;</font></TD></TR>
            <TR>
                <TD class="NArialL" align="right" width="62"> Values:</TD>
                <TD colspan="2" width="195">&nbsp;</TD>
            </TR>
            <% int colno = 0; %>
            <logic:iterate name="list" id="userDefinedField">
                <TR>
                    <TD width="62">&nbsp;</TD>
                    <TD width="128"> <html:text name="userDefinedField" property="value" styleClass="txfield" size="25" maxlength="35" /></TD>
                    <TD><% if ( colno == 0 ) { %> <a href="javascript:addRow('rowId1');"><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center onmouseover="window.status='Click here to add row';return true" title="Click here to add row" onmouseout="window.status='';return true" ></a> <% } %></TD>
                    <% colno++;%>
                </TR>
            </logic:iterate>
            <TR  id="rowId1"><TD colspan="3" ></TD></TR>
            <TR>
                <TD width="62">&nbsp;</TD>
                <TD colspan="2" width="195">&nbsp;</TD>
            </TR>
            <TR>
                <TD colspan="6" align="center" width="263">
                <chiptrack:restrictedLink functionality='<%=Functionality.PROJECT_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:save();" onmouseover="window.status='Click here to Save List Values';return true" onmouseout="window.status='';return true">
                   <IMG onmouseover="window.status='Click here to Save List Values';return true" title="Click here to Save list values" onmouseout="window.status='';return true" height=17 src="<%=chipTracContext%>/jsp/includes/images/save.gif"  width=53 border=0>
                </chiptrack:restrictedLink>&nbsp;&nbsp;&nbsp;&nbsp;
                   <a href="javascript:document.userDefinedFieldsForm.reset();"><IMG onmouseover="window.status='Click to Reset';return true" title="Click here to Reset" onmouseout="window.status='';return true" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 width="53" height="17"></a>
                </TD>
            </TR>
            <TR>
                <TD colspan="6" align="center">
                    <a href="javascript:closeWindow();"  onMouseOver="window.status='Click here to close this window';return true" title='Click here to close this window'><font class='NArialL'><b>[Close this window]</b></font></a>
                </TD>
            </TR>

        </TABLE>

        <input type="hidden" name="action" value="">
        <input type="hidden" name="projectId" value="<%=request.getParameter("projectId")%>">
        <input type="hidden" name="listName" value="<%=request.getParameter("listName")%>" >
        </html:form>
    </TD>
<!-- till here -->
  </TR>
  </TBODY>
</TABLE>
</BODY>
</HTML>


